package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.util.GenerateNum
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.util.*

/**
 * <p>
 * 出库单
 * </p>
 *
 * @author cxw
 * @since 2021-06-10
 */
@NoArg
@TableName("warehouse_out_order")
data class WarehouseOutOrder(

	/**
     * 出库单id
     */
    @TableId(value = "id", type = IdType.AUTO)
    var id: Long,

	/**
     * 部门id
     */
    @TableField("dept_id")
    var deptId: Long = getContext().subCompanyId,

	@TableField(exist = false)
    var deptName: String? = null,


	/**
     * 公司id
     */
    @TableField("company_id")
    var companyId: Long = getContext().companyId,

	/**
     * 创建时间
     */
    @TableField("create_time")
    var createTime: Date = Date(),

	/**
     * 单据时间
     */
    @TableField("order_time")
    var orderTime: Date? = null,

	/**
     * 创建用户
     */
    @TableField("create_user_id")
    var createUserId: Long = getContext().userId,

	/**
     * 出库类型
     */
    @TableField("type")
    var type: TypeEnum = TypeEnum.OTHER,

	/**
     * 操作人
     */
    @TableField("deal_user_id")
    var dealUserId: Long? = null,

	@TableField(exist = false)
    var dealUserName: String? = null,

	/**
     * 处理时间
     */
    @TableField("deal_time")
    var dealTime: Date? = null,

	/**
     * 状态
     */
    @TableField("status")
    var status: Status = Status.UNKNOWN,


	/**
     * 数据有效性
     */
    @TableField("enabled")
    var enabled: Int = 1,

	/**
     * 出库单号
     */
    @TableField("out_order_num")
    var outOrderNum: String = generateOrder("O"),

	/**
     * 实际接收人
     */
    @TableField("out_user_id")
    var outUserId: Long? = null,

	/**
     * 实际接收人名称
     */
    @TableField(exist = false)
    var outUserName: String? = null,

	/**
     * 退货供应商id
     */
    @TableField("supplier_id")
    var supplierId: Long? = null,

	@TableField(exist = false)
    var supplierName: String? = null,

	/**
     * 部门领用id
     */
    @TableField("out_warehouse_dept_id")
    var outWarehouseDeptId: Long? = null,

	@TableField(exist = false)
    var outWarehouseDeptName: String? = null,

	/**
     * 员工领用
     */
    @TableField("out_warehouse_user_id")
    var outWarehouseUserId: Long? = null,

	@TableField(exist = false)
    var outWarehouseUserName: String? = null,

	/**
     * 销售出库（关联订单） 暂未处理
     */
    @TableField("out_warehouse_order_id")
    var outWarehouseOrderId: Long? = null,



	/**
     * 其他
     */
    @TableField("other")
    var other: String? = null,

	/**
     * 出库对象id
     */
    @TableField(exist = false)
    var outTypeObjectId:Long ?= null,
	/**
     * 明细
     */
    @TableField(exist = false)
    var details: List<WarehouseOutOrderDetail>? = null

){

    val outName: String?
        get() {
            return when (type) {
                TypeEnum.WAREHOUSE_OUT_TYPE_SUPPLIER -> supplierName

                TypeEnum.WAREHOUSE_OUT_TYPE_DEPT -> outWarehouseDeptName

                TypeEnum.WAREHOUSE_OUT_TYPE_USER -> outWarehouseUserName
                else -> ""
            }
        }

    val orderIsSelf: Boolean
        get() {
            return createUserId == getContext().userId
        }

    companion object : GenerateNum()
}
